#!/bin/bash

# CONTEXT: GUEST during PRE-CONSTRUCTION as ROOT
# PURPOSE: Setup apt-repo list so that we can connect to Percona's repo

set -e
set -o xtrace

GUEST_USERNAME=${GUEST_USERNAME:-"ubuntu"}
RELEASE=${DIB_RELEASE:-"xenial"}

# Add Percona GPG key
mkdir -p /home/${GUEST_USERNAME}/.gnupg
for server in "pool.sks-keyservers.net" "keys.gnupg.net" "keyserver.ubuntu.com"; do
  apt-key adv --keyserver $server --recv-keys 8507EFA5 && break
done

# Add Percona repo
# Creates the percona sources list
cat <<EOL > /etc/apt/sources.list.d/percona.list
deb http://repo.percona.com/apt $RELEASE main
deb-src http://repo.percona.com/apt $RELEASE main
EOL

# Force an update
apt-get update
